local qice = fk.CreateSkill{
    name = "jinld__qice",
}

Fk:loadTranslationTable{
    ["jinld__qice"] = "棋策",
    [":jinld__qice"] = "与你势力相同的角色使用伤害类应变牌时，你可以弃置一张与此牌类别相同的牌，令此牌无视应变条件，然后若此牌造成伤害，你摸一张牌。",

    ["#jinld__qice_discard"] = "棋策：弃置一张与 %arg 类别相同的牌，令%arg无视应变条件",

    ["$jinld__qice1"] = "辅弼天家，以扶朝纲。",
    ["$jinld__qice2"] = "为国治政，尽忠匡辅。",
}

local H = require "packages/ol_hegemony/util"

qice:addEffect(fk.PreCardUse,{
    anim_type = "support",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(qice.name) and H.compareKingdomWith(player, target) and data.card.is_damage_card
        and data.card.extra_data and data.card.extra_data.heg_variation and data.card:getMark(data.card.extra_data.heg_variation[1]) and not player:isNude()
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local card = room:askToDiscard(player,{
            min_num = 1,
            max_num = 1,
            pattern = ".|.|.|.|.|"..data.card:getTypeString().."|^"..data.card.id,
            skill_name = qice.name,
            prompt = "#jinld__qice_discard:::"..data.card:toLogString(),
            skip = true,
            cancelable = true,
        })
        if #card > 0 then
         event:setCostData(self, {cards = card})
         return true
      end
    end,
    on_use = function (self, event, target, player, data)
        player.room:throwCard(event:getCostData(self).cards, qice.name, player, player)
        data.extra_data = data.extra_data or {}
        data.extra_data.heg_variation_type = {"@fujia-public", "@kongchao-public", "@canqu-public", "@zhuzhan-public", "@heg_yibing-public"}
        data.extra_data.jinld__qice = true
    end,
})

qice:addEffect(fk.CardUseFinished,{
    anim_type = "drawcard",
    is_delay_effect = true,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(qice.name) and data.extra_data and data.extra_data.jinld__qice and data.damageDealt
    end,
    on_use = function (self, event, target, player, data)
        player:drawCards(1, qice.name)
    end
})

return qice